From 3cf05a569ed988a9030208db2483bc548bebc150 Mon Sep 17 00:00:00 2001 From: dianlujitao Date: Wed, 15 May 2019 15:33:27 +0800 Subject: Resolve e2fsdroid failure in certain cases * Set proper SELinux context for system-as-root system, AOSP uses "/" in fstab while TWRP uses "/system_root" so an exception is necessary. * Skip initializing context if the target partition doesn't exist in /file_contexts e.g. /usb-otg. Change-Id: I8f802c34e18fb9f65bf936d11967c83a451b0493 --- partition.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/partition.cpp b/partition.cpp index 88c2cd3a5..e00322b52 100644 --- a/partition.cpp +++ b/partition.cpp @@ -2080,13 +2080,19 @@ bool TWPartition::Wipe_EXTFS(string File_System) { } if (TWFunc::Path_Exists("/sbin/e2fsdroid")) { - // Execute e2fsdroid to initialize selinux context - Command = "e2fsdroid -e -S /file_contexts -a " + Mount_Point + " " + Actual_Block_Device; - LOGINFO("e2fsdroid command: %s\n", Command.c_str()); - ret = TWFunc::Exec_Cmd(Command); - if (ret) { - gui_msg(Msg(msg::kError, "unable_to_wipe=Unable to wipe {1}.")(Display_Name)); - return false; + const string& File_Contexts_Entry = (Mount_Point == "/system_root" ? "/" : Mount_Point); + char *secontext = NULL; + if (!selinux_handle || selabel_lookup(selinux_handle, &secontext, File_Contexts_Entry.c_str(), S_IFDIR) < 0) { + LOGINFO("Cannot lookup security context for '%s'\n", Mount_Point.c_str()); + } else { + // Execute e2fsdroid to initialize selinux context + Command = "e2fsdroid -e -S /file_contexts -a " + File_Contexts_Entry + " " + Actual_Block_Device; + LOGINFO("e2fsdroid command: %s\n", Command.c_str()); + ret = TWFunc::Exec_Cmd(Command); + if (ret) { + gui_msg(Msg(msg::kError, "unable_to_wipe=Unable to wipe {1}.")(Display_Name)); + return false; + } } } else { LOGINFO("e2fsdroid not present\n"); -- cgit v1.2.3